package com.bnz.shop.controller;

import java.util.Arrays;
import java.util.Map;

import com.bnz.pojo.R;
import com.bnz.shop.entity.group.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bnz.shop.entity.GoodsEntity;
import com.bnz.shop.service.GoodsService;
import com.bnz.common.utils.PageUtils;




/**
 * 商品
 *
 * @author zfs
 * @email 903754208@qq.com
 * @date 2022-11-01 12:31:54
 */
@RestController
@RequestMapping("shop/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		GoodsEntity goods = goodsService.getById(id);

        return R.ok().put("goods", goods);
    }
    //根据id查询出来所有的商品信息 商品组合内容
    @RequestMapping("/findById/{id}")
    public R findById(@PathVariable String id){
        //查询出商品的组合对象
       Goods goods = goodsService.findById(id);

       return R.ok().put("goods",goods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody Goods goods){
		goodsService.save(goods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody Goods goods){
		goodsService.update(goods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		goodsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
